package com.rm.freedrawsample.slice;

import com.rm.freedrawsample.IntentHelper;
import com.rm.freedrawsample.ResourceTable;
import com.rm.freedrawview.FreeDrawView;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.agp.components.element.ShapeElement;

/**
 * AbilityScrollableSlice.
 *
 * @author author
 * @version version
 */
public class AbilityScrollableSlice extends AbilitySlice implements Component.ClickedListener {

    private FreeDrawView mDrawSignature;
    private FreeDrawView mDrawSmile;
    private FreeDrawView mDrawSad;
    private FreeDrawView mDrawLeaf;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_scrollable);
        getWindow().setStatusBarColor(getColor(ResourceTable.Color_colorPrimaryDark));
        mDrawSignature = (FreeDrawView) findComponentById(ResourceTable.Id_draw_signature);
        mDrawSmile = (FreeDrawView) findComponentById(ResourceTable.Id_draw_smile);
        mDrawSad = (FreeDrawView) findComponentById(ResourceTable.Id_draw_sad);
        mDrawLeaf = (FreeDrawView) findComponentById(ResourceTable.Id_draw_leaf);
        findComponentById(ResourceTable.Id_ic_github).setClickedListener(this);
        findComponentById(ResourceTable.Id_ic_delete).setClickedListener(this);
        findComponentById(ResourceTable.Id_icon_back).setClickedListener(this);
        TextField textField1 = (TextField) findComponentById(ResourceTable.Id_edit_name);
        ShapeElement cursorShapeElement1 = new ShapeElement(this, ResourceTable.Graphic_cursor_bubble);
        textField1.setBubbleElement(cursorShapeElement1);
        TextField textField2 = (TextField) findComponentById(ResourceTable.Id_edit_age);
        ShapeElement cursorShapeElement2 = new ShapeElement(this, ResourceTable.Graphic_cursor_bubble);
        textField2.setBubbleElement(cursorShapeElement2);
        FocusLine.drawFocusLine(textField1, findComponentById(ResourceTable.Id_component_line1));
        FocusLine.drawFocusLine(textField2, findComponentById(ResourceTable.Id_component_line2));

    }

    @Override
    public void onClick(Component component) {
        int id = component.getId();
        if (id == ResourceTable.Id_ic_github) {
            IntentHelper.openUrl(this, getString(ResourceTable.String_github_url));
        } else if (id == ResourceTable.Id_ic_delete) {
            mDrawSignature.clearDrawAndHistory();
            mDrawSmile.clearDrawAndHistory();
            mDrawSad.clearDrawAndHistory();
            mDrawLeaf.clearDrawAndHistory();
        } else if (id == ResourceTable.Id_icon_back) {
            getAbility().terminateAbility();
        }
    }
}
